home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / aessrc12 / aesfsel2.s < prev    next >
Text File  |  1990-11-23  |  21KB  |  456 lines

  1.  
  2. ;*========================================================================
  3. ;*
  4. ;* AESFAST Public Domain GEM bindings.
  5. ;*  Maintenance:
  6. ;*   02/11/89 v1.1: This source file is new with this version.
  7. ;*
  8. ;*   04/07/89 v1.2: 
  9. ;*            The calculation of the location of the prompt on the
  10. ;*            screen has been changed.  It was placed one boxchar height
  11. ;*            down on the screen, putting it right below the menu bar.
  12. ;*            This didn't look too good on a big-monitor system, so now
  13. ;*            it is calculated by centering the box, then subtracting a
  14. ;*            fixed offset from the centered Y to make it appear right
  15. ;*            above the fsel'er box.  The offset is 9 character heights,
  16. ;*            (plus 2 extra char heights for the prompt itself), less
  17. ;*            2 pixels (just to line everything up real neat).
  18. ;*========================================================================
  19.  
  20.           .include  "aesfast.sh"
  21.           .include  "gemfast.sh"
  22.           .extern   _gl_apversion
  23.           .extern   aesblock
  24.  
  25. ;*************************************************************************
  26. ;*
  27. ;* Extended fsel manager routine.
  28. ;*  (Including simulation routines for pre-TOS 1.4 systems).
  29. ;*
  30. ;*************************************************************************
  31.  
  32. ;-------------------------------------------------------------------------
  33. ; fsel_exinput
  34. ;  This function is new with TOS 1.4, but this binding supports it in all
  35. ;  TOS/AES versions with a simulation of the new routine's actions if the
  36. ;  AES version we're running under is pre-TOS 1.4
  37. ;-------------------------------------------------------------------------
  38.  
  39. _fsel_exinput::
  40.  
  41.           .cargs    #8,.pinpath.l,.pinsel.l,.pbutton.l,.plabel.l
  42.           link      a6,#-4
  43.  
  44.           move.w    _gl_apversion,d0         ; Check the AES version.  If
  45.           cmp.w     #$0104,d0                ; it's $0104, we're running
  46.           beq.s     .ramaes                  ; on the RAM-based TOS 1.4
  47.           cmp.w     #$0130,d0                ; Else, if it's less than $0130
  48.           blt       simu_exinput             ; we have to simulate exinput.
  49. .ramaes:
  50.           move.l    .plabel(a6),d0           ; Swap the button and prompt
  51.           move.l    .pbutton(a6),.plabel(a6) ; string pointers to make the
  52.           move.l    d0,.pbutton(a6)          ; addrin stuff contiguous.
  53.  
  54.           AControl  91,0,2,3                 ; AES v1.3 & up: fsel_exinput
  55.           moveq.l   #-4,d2                   ; is a legal function, do it.
  56.           lea       .pinpath(a6),a0          ; a0 -> addrin
  57.           ACall     RET2HERE                 ; Call AES.
  58.  
  59.           move.l    .plabel(a6),d0           ; Swap the prompt string and
  60.           move.l    .pbutton(a6),.plabel(a6) ; button pointers back to how
  61.           move.l    d0,.pbutton(a6)          ; they were on entry.
  62.  
  63.           moveq.l   #-4,d1                   ; Return values from
  64.           lea       .pbutton(a6),a1          ; intout[] array to caller
  65.           jmp       (a0)                     ; via aes_return routine.
  66.  
  67. ;*************************************************************************
  68. ; The following code and data supports the exinput simulation routines.
  69. ;
  70. ; The simulator supports *most* of the TOS 1.4 features, to wit:
  71. ;
  72. ;  - A prompt string of up to 30 chars is displayed with the file selector.
  73. ;  - The file selector handles <CR> like TOS 1.4 does (see comments below).
  74. ;  - If the caller passes in a path with a leading '\' it will be appended
  75. ;    to the current default drive & path (and the whole resulting string
  76. ;    will be returned upon exit).
  77. ;  - The current DTA is preserved.
  78. ;  - The current drive and path is preserved.
  79. ;
  80. ; These are differences between the simulator and TOS 1.4:
  81. ;
  82. ;  - There are no drive buttons in the dialog.
  83. ;  - There is still a static limit of 100 files that can be displayed.
  84. ;  - Long pathnames are NOT handled correctly.
  85. ;  - Multiple abort/continue situations will still give problems.
  86. ;  - The redraw sequence of the dialog is still the same.
  87. ;
  88. ; The things not supported are, of course, things I can't affect without
  89. ; completely re-writing the fsel_input handler.
  90. ;*************************************************************************
  91.  
  92. ;-------------------------------------------------------------------------
  93. ; Define variables which will be accessed as offsets from a3.
  94. ;  (Storage for these things will be allocated from the stack at runtime).
  95. ;-------------------------------------------------------------------------
  96.  
  97.           .abs                ; Define offsets from a3 base register...
  98.           
  99. savddrv:  ds.w      1         ; Save default drive.
  100. savdpath: ds.b      128       ; Save default path.
  101. savipath: ds.b      128       ; Save input path for compare after <CR>.
  102. savdta:   ds.l      1         ; Save pointer to current DTA.
  103. tmpdta:   ds.b      44        ; Temporary DTA for fsel_input to use.
  104. SAV_SZ    =  *                ; Size of a3-relative storage.
  105.  
  106. ;-------------------------------------------------------------------------
  107. ; Define variables which will be accessed as offsets from a5.
  108. ;  (Storage for these things is allocated in the text segment, below).
  109. ;-------------------------------------------------------------------------
  110.  
  111.           .abs                ; Define offsets from a5 base register...
  112.           
  113. prmpflag: ds.w      1         ; Flag: Has one-time object fixup been done?
  114.  
  115. treeptr:  ds.l      1         ; Ptr to tree: addrin for objc_draw() et. al.
  116. azero:    ds.w      1         ; A handy zero.
  117.  
  118. dialstuf: ds.w      1         ; Here things get a little ugly: The storage 
  119.           ds.w      2         ; from 'dialstuff' down is the intin array
  120. prmpstob: ds.w      1         ; for form_dial(FMD_FINISH).  From prmpstob
  121. prmpdpth: ds.w      1         ; down, it is also the intin array for
  122. prmpclip: ds.w      4         ; objc_draw().
  123.  
  124. lastkeyCR:ds.w      1         ; Flag: was last keystroke during fsel a <CR>?
  125.  
  126. ABS_SZ    =  *                ; Size of the a5-relative storage block.
  127.  
  128.           .text
  129.  
  130. absstore: dcb.b     ABS_SZ,0  ; Set aside memory for the a5-relative block.
  131.  
  132. ;-------------------------------------------------------------------------
  133. ; Define the TEDINFO and OBJECT structures for the prompt text. 
  134. ; (Macros for defining these things come from gemfast.sh).
  135. ;-------------------------------------------------------------------------
  136.  
  137. YSZ_PROMPT = 2
  138. YSZ_FSEL   = 9
  139. Y_OFFSET   = YSZ_PROMPT+YSZ_FSEL
  140.  
  141. prmptext: Teddef    0,0,0,3,0,TE_CNTR,$1180,0,1,31,0
  142. prmptree: Treedef   text
  143.           Objdef    ,-1,-1,-1,G_BOXTEXT,LASTOB,NORMAL,0,0,0,40,YSZ_PROMPT
  144.  
  145. ;-------------------------------------------------------------------------
  146. ; This routine is installed as a hook in the BIOS vector for the duration
  147. ; of the the fsel_input call.  It watches for a Bconin(2) call (which will
  148. ; be the AES asking for a character).  The Bconin call is done from in
  149. ; here such that we get the character back from the real BIOS and examine
  150. ; it.  If the character is a <CR>, we set the flag to say so and return
  151. ; the character to the caller.  If not a <CR> we clear the flag and 
  152. ; return the character.
  153. ;
  154. ; The whole reason for this is a bug in the pre-TOS 1.4 AES: If the user
  155. ; edited the path but didn't click the mouse on anything or change the
  156. ; filename field, then hit <CR>, the system returned a CANCEL status. This
  157. ; BIOS hook is the only way to tell for sure that the exit was via <CR>.
  158. ;-------------------------------------------------------------------------
  159.  
  160. oldbios:  dc.l      0         ; Old BIOS vector address.
  161.  
  162. bioshook:
  163.           lea       6(sp),a0            ; Assume super mode caller.
  164.           btst.b    #5,(sp)             ; Were we in super mode?
  165.           bne.s     .supermode          ; No, user mode...
  166.           move.l    usp,a0              ; So look at parms on user stack.
  167. .supermode:
  168.           move.l    #$00020002,d0       ; Bconin(2) function...
  169.           cmp.l     (a0),d0             ; Is it that?
  170.           bne.s     .biospunt           ; Nope, punt.
  171.  
  172.           move.l    d0,-(sp)            ; Stack Bconin(2) function code,
  173.           bsr.s     .bioscall           ; Go get the character.
  174.           addq.l    #4,sp
  175.           
  176.           lea       absstore(pc),a0     ; Point to common storage base.
  177.           cmp.b     #'\r',d0            ; Is the char a <CR>? If so set the
  178.           seq       lastkeyCR(a0)       ; flag, either way, return the char.
  179. .biosreturn:  
  180.           rte                           ; Return the char to the caller.
  181.  
  182. .bioscall:                              ; Call original BIOS, with return
  183.           move.w    sr,-(sp)            ; to caller of 'bioscall'.
  184. .biospunt:                              
  185.           move.l    oldbios(pc),-(sp)   ; Not a BIOS function we handle,
  186.           rts                           ; punt control to the real BIOS.
  187.           
  188. ;-------------------------------------------------------------------------
  189. ; This routine lets us call AES more quickly than going through the
  190. ; routines in AESCOMN (and is better tailored to our needs here).
  191. ;-------------------------------------------------------------------------
  192.           
  193. aes_icall:
  194.            
  195.           movep.l   d0,control+1(a4)    ; fill in the control array (!),
  196.           move.l    a0,padrin(a4)       ; store the adrin ptr into aespb
  197.           move.l    a1,pintin(a4)       ; store the intin ptr into aespb
  198.           move.l    a2,pintout(a4)      ; store it into aespb
  199.           move.l    a4,d1               ; move the aespb pointer to the
  200.           move.w    #$C8,d0             ; interface register, also the AES
  201.           trap      #2                  ; function code, call AES, return
  202.           rts                           ; to the calling binding routine.
  203.  
  204. ;-------------------------------------------------------------------------
  205. ; simu_exinput - Simulate an exinput call on pre-TOS 1.4 systems.
  206. ;-------------------------------------------------------------------------
  207.  
  208. simuregs  reg       a2-a5               ; Registers we use.
  209.  
  210. simu_exinput:
  211.  
  212.           movem.l   #simuregs,-(sp)     ; Save registers.
  213.           lea       absstore(pc),a5     ; Load storage base register.
  214.           lea       aesblock,a4         ; Load aesblock base register.
  215.           
  216.           tas       prmpflag(a5)        ; Has first-time object tree fixup
  217.           bne       do_simulation       ; been done?  If so, continue below.
  218.  
  219. ;-------------------------------------------------------------------------
  220. ; Do the one-time object tree fixup:
  221. ;
  222. ;  - Plug in the various static string pointers.
  223. ;  - Plug in a couple of static integer values.
  224. ;  - Call rsrc_obfix  for resolution-specific x/y/w/h fixup.
  225. ;  - Call form_center to center box in the x coord & calc the clip area.
  226. ;  - Call graf_handle to get the height of a boxchar, and use this height
  227. ;    as the ob_y of the prompt box (and the clip area).  It just so happens
  228. ;    that the AES menu bar is one 'boxchar' in height, so this guarantees
  229. ;    we never overlay the menu bar with our prompt.
  230. ;-------------------------------------------------------------------------
  231.          
  232.           lea       azero(a5),a1        ; To do fixup, set string pointers
  233.           lea       prmptext(pc),a0     ; in TEDINFO and OBJECT structures.
  234.           move.l    a1,te_ptmplt(a0)    ; The template and valid strings
  235.           move.l    a1,te_pvalid(a0)    ; are NULL.  The ob_spec pointer
  236.           lea       prmptree(pc),a3     ; in the tree must point to the
  237.           move.l    a0,ob_spec(a3)      ; TEDINFO structure.
  238.           move.l    a3,treeptr(a5)      ; Save the tree pointer.
  239.  
  240.           move.w    #MAX_DEPTH,prmpdpth(a5)   ; Set objc_draw max-depth.
  241.           move.w    #FMD_FINISH,dialstuf(a5)  ; Set form_dial type.
  242.           
  243.           subq.l    #2,sp               ; allocate intout[1] 
  244.           move.l    sp,a2               ; a2 -> intout
  245.           lea       azero(a5),a1        ; a1 -> intin 
  246.           lea       treeptr(a5),a0      ; a0 -> adrin
  247.           AControl  114,1,1,1           ;    rsrc_obfix(prmptree,R_TREE);
  248.           bsr       aes_icall           ; do it.
  249.           addq.l    #2,sp               ; we don't care about intout[0].
  250.  
  251.           sub.w     #10,sp              ; Allocate intout[5] 
  252.           move.l    sp,a2               ; a2 -> intout
  253.           lea       treeptr(a5),a0      ; a0 -> addrin (prmptree)
  254.           AControl  54,0,5,1            ;    form_center(prmptree, &stack);
  255.           bsr       aes_icall           ; do it.
  256.           addq.l    #2,sp               ; We don't care about intout[0],
  257.           move.l    (sp)+,prmpclip(a5)  ; the rest of intout is the
  258.           move.l    (sp)+,prmpclip+4(a5); clip rectangle, save it.
  259.  
  260.           sub.w     #10,sp              ; Allocate intout[5], make a2 point
  261.           move.l    sp,a2               ; to it.  Do graf_handle(&stack).
  262.           AControl  77,0,5,0            ; The only value we want back from
  263.           bsr       aes_icall           ; the call is the height of a char
  264.           addq.l    #4,sp               ; which is in intout[2], put that
  265.           move.w    (sp)+,d0            ; in d0, throw everything else away.
  266.           addq.l    #4,sp               ; Calc the placement of the prompt
  267.           mulu      #Y_OFFSET,d0        ; box as Y_OFFSET characters up from
  268.           subq.w    #2,d0               ; the current (centered) location,
  269.           sub.w     d0,ob_y(a3)         ; set the ob_y value in the tree
  270.           sub.w     d0,prmpclip+2(a5)   ; and clip rectange to this value.
  271.  
  272. strcpy:
  273.           move.b    (a0)+,(a1)+
  274.           bne.s     strcpy
  275.           rts
  276.  
  277. strcmp:
  278.           move.b    (a0)+,d0
  279.           beq.s     .checkdone
  280.           cmp.b     (a1)+,d0
  281.           beq.s     strcmp
  282.           rts
  283. .checkdone:
  284.           tst.b     (a1)
  285.           rts
  286.  
  287. ;-------------------------------------------------------------------------
  288. ; Once the one-time stuff is done (and on all subsequent calls...) do
  289. ; the actual simulation of the TOS 1.4 exinput:
  290. ;
  291. ;  - Plug the prompt string pointer into the TEDINFO.
  292. ;  - The current default drive and path is saved.
  293. ;  - The current DTA address is saved, and a temporary DTA is installed.
  294. ;  - If the pathname passed to exinput starts with a '\', the passed-in
  295. ;    path is appended to the current default path.
  296. ;  - A hook is placed into the BIOS vector to watch for <CR> being hit,
  297. ;    so that we can mimick the new fsel's actions when just the pathname
  298. ;    is edited, and the user hits <CR> (to move to the filename field).
  299. ;  - The prompt string is placed in a box above the fsel dialog box on the
  300. ;    screen (but below the menu bar) before the system fsel'er is called.
  301. ;    The prompt is displayed inside a box, (it's a BOXTEXT object, which
  302. ;    is the entire tree).  The prompt is displayed with an objc_draw, and
  303. ;    removed by sending a redraw message (via form_dial).
  304. ;  - Call fsel_input() (the old one).
  305. ;  - Check to see if our BIOS hook set the flag saying a <CR> was the last
  306. ;    key hit.  If so, see if the pathname in the fsel dialog was changed.
  307. ;    If so, the user probably hit <CR> after typing the path (I always do),
  308. ;    so we loop back to do the fsel dialog again.  If the user clicked on
  309. ;    OK instead of hitting return, this won't happen.  Also, if the user
  310. ;    doesn't change the path (but perhaps does change the filename), then
  311. ;    hits return, we will not repeat the dialog.
  312. ;  - Call form_dial() to send a redraw message to clear the prompt box.
  313. ;  - Restore the current drive & path, and the old DTA.
  314. ;  - De-install the BIOS hook.
  315. ;  - Return to caller.
  316. ;-------------------------------------------------------------------------
  317.  
  318. do_simulation:
  319.  
  320.           .cargs    #8,.pinpath.l,.pinsel.l,.pbutton.l,.plabel.l
  321.  
  322.           sub.w     #SAV_SZ,sp          ; Allocate save area from stack,
  323.           move.l    sp,a3               ; load save area base register.
  324.                     
  325.           move.w    #$19,-(sp)
  326.           trap      #1
  327.           addq.l    #2,sp
  328.           move.w    d0,savddrv(a3)
  329.           add.b     #'A',d0
  330.           move.b    d0,savdpath(a3)
  331.           move.b    #':',1+savdpath(a3)
  332.           
  333.           clr.w     -(sp)
  334.           pea       2+savdpath(a3)
  335.           move.w    #$47,-(sp)
  336.           trap      #1
  337.           addq.l    #8,sp
  338.           
  339.           tst.b     2+savdpath(a3)
  340.           bne.s     .gotpath
  341.           move.w    #$5C00,2+savdpath(a3)         ; 5C00 == "\<NULL>"
  342.  
  343. .gotpath:
  344.  
  345.           move.w    #$2F,-(sp)
  346.           trap      #1
  347.           move.l    d0,savdta(a3)
  348.           addq.l    #2,sp
  349.  
  350.           pea       tmpdta(a3)
  351.           move.w    #$1A,-(sp)
  352.           trap      #1
  353.           addq.l    #6,sp
  354.  
  355.           move.l    .pinpath(a6),a0     ; a0 -> input path
  356.           lea       savipath(a3),a1     ; a0 -> path save area
  357.           cmp.b     #'\\',(a0)          ; Leading '\' in input path?
  358.           bne.s     .copypath           ; Nope, go do straight copy.
  359.           lea       savdpath(a3),a0     ; Yep, so copy the current
  360.           bsr       strcpy              ; default path to the save
  361.           cmp.b     #'\\',-2(a1)
  362.           bne.s     .noterm
  363.           subq.l    #1,a1
  364. .noterm:
  365.           move.l    .pinpath(a6),a0     ; area first, then concat
  366.           subq.l    #1,a1               ; the input path onto the 
  367.           bsr       strcpy              ; end of it.  Since we changed
  368.           lea       savipath(a3),a0     ; it in the save area, we need to
  369.           move.l    .pinpath(a6),a1     ; copy it back to the input area.
  370. .copypath:
  371.           bsr       strcpy
  372.  
  373.           lea       prmptext(pc),a0     ; a0 -> te_ptext in TEDINFO.
  374.           move.l    .plabel(a6),(a0)    ; Set prompt text pointer.
  375.           
  376.           subq.l    #2,sp               ; allocate intout[1]
  377.           move.l    sp,a2               ; a2 -> intout
  378.           lea       prmpstob(a5),a1     ; a1 -> intin
  379.           lea       treeptr(a5),a0      ; a0 -> addrin
  380.           AControl  42,6,1,1            ;    objc_draw(prmptree,R_TREE....);
  381.           bsr       aes_icall           ; do it.
  382.           addq.l    #2,sp               ; throw away intout[0].
  383.           
  384.           pea       bioshook(pc)
  385.           move.w    #$2D,-(sp)
  386.           move.w    #5,-(sp)
  387.           trap      #13
  388.           addq.l    #8,sp
  389.           lea       oldbios(pc),a0
  390.           move.l    d0,(a0)
  391.  
  392. .fsel_loop:
  393.  
  394.           clr.w     lastkeyCR(a5)       ; Clear <CR> flag.
  395.           
  396.           lea       -4(a6),a2           ; a2 -> intout
  397.           lea       .pinpath(a6),a0     ; a0 -> addrin          
  398.           AControl  90,0,2,2            ;    fsel_input(inpath, insel,...);
  399.           bsr       aes_icall           ; do it.
  400.  
  401.           tst.w     lastkeyCR(a5)       ; Hack to fix an AES bug: If our
  402.           beq.s     .fsel_done          ; BIOS hook says the last key was
  403.           move.w    #1,-2(a6)           ; a CR, force the button to OK.
  404.  
  405.           move.l    .pinpath(a6),a0
  406.           lea       savipath(a3),a1
  407.           bsr       strcmp
  408.           beq.s     .fsel_done
  409.           
  410.           move.l    .pinpath(a6),a0
  411.           lea       savipath(a3),a1
  412.           bsr       strcpy
  413.           bra.s     .fsel_loop
  414.           
  415. .fsel_done:
  416.  
  417.           subq.l    #2,sp               ; allocate intout[1] for form_dial
  418.           move.l    sp,a2               ; a2 -> intout
  419.           lea       dialstuf(a5),a1     ; a1 -> intin
  420.           AControl  51,9,1,0            ;    form_dial(FMD_FINISH,...);
  421.           bsr       aes_icall           ; this sends a redraw message to
  422.           addq.l    #2,sp               ; clean up our prompt text box.
  423.  
  424.           move.w    savddrv(a3),-(sp)
  425.           move.w    #$0E,-(sp)
  426.           trap      #1
  427.           addq.l    #4,sp
  428.           
  429.           pea       savdpath(a3)
  430.           move.w    #$3B,-(sp)
  431.           trap      #1
  432.           addq.l    #6,sp
  433.  
  434.           move.l    savdta(a3),-(sp)
  435.           move.w    #$1A,-(sp)
  436.           trap      #1
  437.           addq.l    #6,sp
  438.  
  439.           move.l    oldbios(pc),-(sp)
  440.           move.w    #$2D,-(sp)
  441.           move.w    #5,-(sp)
  442.           trap      #13
  443.           addq.l    #8,sp
  444.  
  445.           add.w     #SAV_SZ,sp          ; Deallocate save area from stack.
  446.           movem.l   (sp)+,#simuregs     ; Restore working regs.
  447.           
  448.           move.l    .pbutton(a6),a1     ; Return the values from
  449.           move.w    -4(a6),d0           ; intout to the caller.
  450.           move.w    -2(a6),(a1)
  451.           unlk      a6
  452.           rts
  453.  
  454. ;         end of code
  455.  
  456.